package com.example.tool.fragment;

import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.example.tool.R;
import com.example.tool.dao.entity.HealthIndexDomain;
import com.example.tool.mvp.CommonPresent;
import com.example.tool.util.CalendarUtil;
import com.example.tool.widget.NumTextView;
import com.example.tool.widget.keep.bar.BarChartView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

import static com.example.tool.util.CalendarUtil.DATE_FORMAT_YMD;

/**
 * Created by liangkun on 2018/8/16.
 * 作用:统计基类
 */

public abstract class BaseCountFragment extends BaseMvpFragment<CommonPresent>  {
    @BindView(R.id.rv_date)
    protected RecyclerView recyclerView;

    @BindView(R.id.bar_chart)
    protected BarChartView barChartView;
    @BindView(R.id.scroll_view)
    protected NestedScrollView scrollView;

    @BindView(R.id.tv_count_index)
    protected NumTextView tvCountIndex; //指数
    @BindView(R.id.tv_finish_count)
    protected NumTextView tvFinishCount; //完成行为个数

    @BindView(R.id.tv_keep_days)
    protected NumTextView tvKeepDays; //指数
    @BindView(R.id.tv_cutoff_time)
    protected TextView tvCutTime; //截止时间
    @BindView(R.id.tv_table_index)
    protected TextView tvTabIndex; //指數說明


//    private ArrayList<Integer> list; //假数据
    protected ArrayList<Float> barList = new ArrayList<>(); //bar的高度

    protected int[] taskImages; //图片
    protected String[] countTags; //标题
    protected String[] countHints; //提示
    protected ArrayList<Integer> indexList = new ArrayList<>(); //指数
    protected ArrayList<Integer> taskList = new ArrayList<>(); //完成任务
    protected ArrayList<Integer> daysList = new ArrayList<>(); //累积坚持

    @Override
    protected CommonPresent createPresenter() {

        return new CommonPresent();
    }

    @Override
    protected void initData() {

        barChartView.setMin(0);
        barChartView.setMax(29);
        barChartView.setSpace(1f);

        List<HealthIndexDomain> domains = presenter.getIndexData();
        setBarData(domains);


    }

    public void setBarPoint() {
        barChartView.setCurrent(29);
    }

    @Override
    protected void initView() {
        recyclerView.setNestedScrollingEnabled(false);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        scrollView.smoothScrollTo(0, 0);
        initCurrentDay();
    }

    protected void initCurrentDay() {
        //日期
        String month = CalendarUtil.getMonthFromDate(CalendarUtil.getCurrentDate(DATE_FORMAT_YMD));
        String day = CalendarUtil.getDayFromDate(CalendarUtil.getCurrentDate(DATE_FORMAT_YMD));
        String HhMm = CalendarUtil.getHhMm();
        tvCutTime.setText(String.format(getString(R.string.current_cutoff_time), month, day, HhMm));
    }

    @Override
    protected int getLayoutId() {
        return R.layout.common_count_fragment;
    }


    /**
     * 子类实现逻辑数据
     *
     * @param indexVos 数据
     */
    protected abstract void setBarData(List<HealthIndexDomain> indexVos);
}
